package com.gusti.common.controller.user;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.gusti.common.form.CalendarForm;
import com.gusti.common.services.ICalendarServices;
import com.gusti.common.vos.RolUsuario;
import com.gusti.common.vos.Usuario;

@Controller
@RequestMapping(value = "/user/")
public class UserController {
	
	@Autowired
	private ICalendarServices calendarServices;
	
	@RequestMapping(value = "home.do", method = RequestMethod.GET)
	public ModelAndView showHome( HttpSession session ){

		Usuario user = (Usuario) session.getAttribute( "user" );
		if( user != null && user.getRolUsuario() == RolUsuario.USUARIO ){
			return new ModelAndView( "/user/index", "user", user.getNombre() );
		}else{
			return new ModelAndView( "/error" );
		}
	}

	@RequestMapping(value = "home/calendar.do", method = RequestMethod.POST)
	public ModelAndView showCalendar( Map<String, Object> model ){

		ArrayList<String> fechas = calendarServices.getFechasString();
		for( int i=0; i < fechas.size(); i++ ){
			model.put( "dia" + String.valueOf( i+1 ), fechas.get( i ) );
		}
		return new ModelAndView( "/user/calendar/calendar", "model", model );
	}
	
	@RequestMapping(value = "home/calendar/content.do", method = RequestMethod.POST)
	public ModelAndView showCalendarContent(){
		
		return new ModelAndView( "/user/calendar/calendarContent" );
	}

	@RequestMapping(value = "home/calendar/content/save.do", method = RequestMethod.POST)
	public void saveCalendar( Map<String, Object> model, CalendarForm calendarForm ) throws Exception{
		
	}
	
}
